'use strict'

define([ 'jquery', 'bootstrap', 'select2', 'shiftform', 'validate',
    'validate.en', 'datetimepicker', 'countdown'], function($) {
  return {
    init : function() {
      this.duringTime = 20*60;
      this.towMinute = 2*60;
      this.fiveSeconds= 5;
      this.initPage();
      this.countDownTime();
    },
      
    initPage : function() {
    	
    	$(document).on("click", ".accessory-modal", function() {
            $('#accessoryModal').modal()
          })
      
    },
    
    countDownTime: function() {
      var that = this;
      var minute = that.duringTime;
      
      $(".countdown-timer").flipcountdown({
        tick: function() {
          var minutes, seconds;
          var countMinute = minute;
          
          minutes = parseInt(countMinute/60) > 9 ? parseInt(countMinute/60) : '0'+ parseInt(countMinute/60)
          seconds = parseInt(countMinute%60) > 9 ? parseInt(countMinute%60) : '0'+ parseInt(countMinute%60)
          
          countMinute = minute--;
          
          if(countMinute == that.towMinute) {
            that.openModal()
          }
          
          if(countMinute == that.fiveSeconds) {
            $(".redirectModal").modal();
            that.countNum();
          }
          
           return minutes +" "+ seconds
        }
      });
    },
    
    openModal: function() {
      var modalHtml = 
      $(".timeinfomodal").modal();
      setTimeout(function() {
        $(".timeinfomodal").modal('hide')
      }, 5000)
      
      $(document).on("click", ".join-meeting", function() {
        $(".timeinfomodal").modal('hide');
      })
    },
    
    countNum: function() {
      var i = 5;
      $(".redirectModal .time").flipcountdown({
        tick: function() {
           $(".redirectModal .time").html(i--)
           
           if(i<2) {
             window.location.href = window.__CTX__.root + '/sessions/1/guest-meetings/1/scoring'
           }
        }
      });
    }
  }
})